
export default class Point {

  /** @type {number} */
  x = 0;

  /** @type {number} */
  y = 0;

  /**
   * @param {number} x 
   * @param {number} y 
   */
  constructor (x, y) {
    this.set(x, y);
  }

  /**
   * @param {number} x 
   * @param {number} y 
   */
  set(x, y) {
    this.x = x || 0;
    this.y = y || 0;
  }

  /**
   * @param {Point} point 
   */
  copy(point) {
    this.x = point.x || 0;
    this.y = point.y || 0;
    return this;
  }

  /**
   * @param {number} x 
   * @param {number} y 
   */
  multiply(x, y) {
    this.x *= x || 1;
    this.y *= y || 1;
    return this;
  }

  /**
   * @param {number} x 
   * @param {number} y 
   */
  divide(x, y) {
    this.x /= x || 1;
    this.y /= y || 1;
    return this;
  }

  /**
   * @param {number} x 
   * @param {number} y 
   */
  add(x, y) {
    this.x += x || 0;
    this.y += y || 0;
    return this;
  }
  
  /**
   * @param {number} x 
   * @param {number} y 
   */
  subtract(x, y) {
    this.x -= x || 0;
    this.y -= y || 0;
    return this;
  }

  /**
   * @param {number} min 
   * @param {number} max 
   */
  clampX(min, max) {
    this.x = Math.max(min, Math.min(this.x, max));
    return this;
  }
  
  /**
   * @param {number} min 
   * @param {number} max 
   */
  clampY(min, max) {
    this.y = Math.max(min, Math.min(this.y, max));
    return this;
  }

  flipX() {
    this.x *= -1;
    return this;
  }

  flipY() {
    this.y *= -1;
    return this;
  }
}
